﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace bat_sym.SimulationLogic.Rules
{
    class Eating : ISimulationRule
    {
        private Random _rng;
        public override void Execute(System.Collections.ObjectModel.ObservableCollection<Models.Bat> bats)
        {
            var dead = new List<Models.Bat>();
            foreach (Models.Bat bat in bats.Where(bat => bat.alive))
            {
                if (bat.FoodAmmount >= 45)
                {
                    bat.FoodAmmount -= 35 + _rng.Next() % 11;
                }
                else
                {
                    if (bat.FoodAmmount >= 35)
                    {
                        bat.FoodAmmount = 0;
                    }
                    else
                    {
                        bat.FoodAmmount = -1;
                        bat.alive = false;
                        dead.Add(bat);
                    }
                }
            }

            foreach (Models.Bat bat in dead)
            {
                bats.Remove(bat);
            }
        }
        public Eating()
        {
            _rng = new Random();
            RuleName = "Eating";
        }
    }
}
